<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="85px"
    >
      <el-form-item label="关联ID:" prop="kqId">
        <el-input
          v-model="queryParams.kqId"
          placeholder="请输入关联ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称:" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <br />
      <el-form-item label="采购单位:" prop="buyer">
        <el-input
          v-model="queryParams.buyer"
          placeholder="请输入采购单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商:" prop="seller">
        <el-input
          v-model="queryParams.seller"
          placeholder="请输入供应商"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
        >重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="kqAllProjectsList" height="630" stripe>
      <el-table-column label="kqId" align="left" prop="kqId" width="80" />
      <el-table-column label="发布时间" align="left" prop="releaseDate" width="100" sortable />
      <el-table-column label="项目名称" align="left" prop="projectName" width="500">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.projectName"
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="CopyFileUrl(scope.row.projectName)"
          />
          {{ scope.row.projectName }}
        </template>
      </el-table-column>
      <el-table-column label="采购人" align="left" prop="buyer" width="300" sortable>
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.buyer"
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="CopyFileUrl(scope.row.buyer)"
          />
          {{ scope.row.buyer }}
        </template>
      </el-table-column>
      <el-table-column label="供应商" align="left" prop="seller" width="300" sortable>
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.seller"
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="CopyFileUrl(scope.row.seller)"
          />
          {{ scope.row.seller }}
        </template>
      </el-table-column>
      <el-table-column label="省份" align="left" prop="province" width="80" />
      <el-table-column label="类型" align="left" prop="projectType" width="80" />
      <el-table-column label="中标金额" align="left" prop="number" />

    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page-sizes="[10, 20, 50, 100, 200, 300, 400, 500]"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getKqProjectsList } from "@/api/work/project";
export default {
  name: "Work",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      kqAllProjectsList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20
        // compName: undefined,
        // collaborator: undefined
        // city: undefined,
        // district: undefined
      },
      // 表单参数
      form: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      getKqProjectsList(this.queryParams).then((res) => {
        this.kqAllProjectsList = res.data.results;
        this.total = res.data.count;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    CopyFileUrl(values) {
      const input = document.createElement("input");
      document.body.appendChild(input);
      input.setAttribute("value", values);
      input.select();
      if (document.execCommand("copy")) {
        document.execCommand("copy");
        this.msgSuccess("复制成功");
      }
      document.body.removeChild(input);
    }
    /** 导出按钮操作 */
    // handleExport() {
    //   const queryParams = this.queryParams;
    //   this.$confirm("是否确认导出所有岗位数据项?", "警告", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning"
    //   })
    //     .then(function() {
    //       return exportKqPumpsInfos(queryParams);
    //     })
    //     .then((response) => {
    //       this.download(response.data.file_url, response.data.name);
    //     });
    // }
  }
};
</script>
